#include "ProcessWinHandleToID.h"

DWORD GetProcessIDbyProcessHandleZw(HANDLE hProcess)
{
	HINSTANCE hNtDll = LoadLibraryW(L"ntdll.dll");
	if (hNtDll == NULL)    return 0xffffffff;
	PFN_ZWQUERYINFORMATIONPROCESS fnProcInfo = PFN_ZWQUERYINFORMATIONPROCESS(
		::GetProcAddress(hNtDll, "ZwQueryInformationProcess"));
	if (fnProcInfo == NULL)
	{
		return 0xffffffff;
	}
	PROCESS_BASIC_INFORMATION pbi;
	ZeroMemory(&pbi, sizeof(PROCESS_BASIC_INFORMATION));
	if (fnProcInfo(hProcess, 0, &pbi, sizeof(PROCESS_BASIC_INFORMATION), NULL) == 0)
	{
		return pbi.UniqueProcessId;
	}
	else
	{
		return 0xffffffff;
	}
}
